package com.林子祺.CAT旅游系统.view.login;

import com.林子祺.CAT旅游系统.controller.login.RegAccount;
import com.林子祺.CAT旅游系统.entity.login.LoginStatus;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import static com.林子祺.CAT旅游系统.view.login.Login.ls;

public class Register {

    public static void register(){
        JFrame jf = new JFrame("注册界面");
        jf.setSize(250, 200);
        jf.setLocationRelativeTo(null);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        JPanel panel = new JPanel(null);

        JLabel label01 = new JLabel();
        JLabel label02 = new JLabel();
        label01.setText("用户名");
        label01.setLocation(20,30);
        label01.setSize(40,25);
        label01.setFont(new Font(null, Font.PLAIN, 10));  // 设置字体，null 表示使用默认字体
        panel.add(label01);
        label02.setText("密码");
        label02.setLocation(20,70);
        label02.setSize(30,25);
        label02.setFont(new Font(null, Font.PLAIN, 10));  // 设置字体，null 表示使用默认字体
        panel.add(label02);

        // 创建文本框，指定可见列数为8列
        JTextField textField = new JTextField();
        textField.setFont(new Font(null, Font.PLAIN, 12));
        textField.setLocation(65,35);
        textField.setSize(150,20);

        // 创建一个按钮，点击后获取文本框中的文本
        JButton btn = new JButton("提交");
        btn.setLocation(100,100);
        btn.setSize(70,20);
        btn.setFont(new Font(null, Font.PLAIN, 10));
        JButton btn2 = new JButton("返回");
        btn2.setLocation(15,135);
        btn2.setSize(70,20);
        btn2.setFont(new Font(null, Font.PLAIN, 10));
        final JPasswordField passwordField = new JPasswordField(10);
        passwordField.setLocation(65,70);
        passwordField.setSize(150,20);


        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ls.nameConfirm = textField.getText();
                ls.passwordConfirm = new String(passwordField.getPassword());
                RegAccount.reg(LoginStatus.nameConfirm, LoginStatus.passwordConfirm);
                jf.dispose();
            }
        });

        btn2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    Login.login();
                } catch (AWTException awtException) {
                    awtException.printStackTrace();
                }
                jf.dispose();
            }
        });

        panel.add(textField);
        panel.add(btn);
        panel.add(btn2);
        panel.add(passwordField);
        jf.setContentPane(panel);
        jf.setVisible(true);

    }

}
